<?php
class Common_Masterlist
{
	private $intNumItems = 10000;
	private $strMemKey = null;
	private $cache = null;
	private $intTimeExpired = 900;
	
	public function __construct($p_strMemKey)
	{
		$this->strMemKey = $p_strMemKey;
		$this->cache = Zend_Registry::get('cache');
	}
	
	public function set($p_intId)
	{
		$strId = $this->strMemKey.$this->getPage($p_intId);
		$arrData = array();
		$arrData = $this->cache->load($strId);
		if ( !isset($arrData[$p_intId]) || !$arrData[$p_intId] )
		{
			$arrData[$p_intId] = $this->getTimeExpired();
			$this->cache->save($arrData, $strId);
		}
	}
	
	public function get($p_intPage)
	{
		return $this->cache->load($this->strMemKey.$p_intPage);
	}
	
	private function getPage($p_intId)
	{
		return floor($p_intId/$this->intNumItems);
	}
	
	public function getTimeExpired()
	{
		return time() + $this->intTimeExpired;
	}
	
	public function getTotal($p_intMaxId)
	{
		return ceil($p_intMaxId/$this->intNumItems)+1;
	}
	
	public function resetTimeExpired($p_arrData, $p_intPage)
	{
		$strId = $this->strMemKey.$p_intPage;
		return $this->cache->save($p_arrData, $strId);
	}
}
?>